<?php
$service = new sqlServicesFunctions();
$allAnrede = $service->getAnrede();
$aerzte = $service->getAllAerzte();
$zeiten = $service->getZeiten();
$allTitel = $service->getTitel();
?>

<html lang="de">
<head>
<meta charset="utf-8">

<link rel="stylesheet"
	href="jquery-ui-1.10.4.custom/development-bundle/themes/custom-theme/jquery-ui.css">
<link rel="stylesheet" href="style.css">

<script>

	$(function() {
		$('#formulardiv').hide();
		$('#neuerArzt').hide();
    	$( "input[type=button], a, button" )
      	.button()
      	.click(function( event ) {
        	event.preventDefault();
      	});
	});
</script>
</head>
<body>
<script type="text/javascript">

function auswahlRow(btn) {
	$('#neuerArzt').hide();
	$('#neuesPasswort').show();
	$('#speichern').show();
	var row = btn.parentNode.parentNode;
	var cells = row.cells;
	$('#btnID')				.val(btn);
	$('#benutzernameA')		.val(cells[0].innerHTML);
	$('#anredeSelectA')		.val(cells[1].innerHTML);
	$('#titelSelectA')		.val(cells[2].innerHTML);
	$('#vornameInputA')		.val(cells[3].innerHTML); 
	$('#nameInputA')		.val(cells[4].innerHTML); 
	$('#strasseInputA')		.val(cells[5].innerHTML); 
	$('#hausnrInputA')		.val(cells[6].innerHTML);
	$('#plzInputA')			.val(cells[7].innerHTML); 
	$('#ortInputA')			.val(cells[8].innerHTML); 
	$('#telefonInputA'	)	.val(cells[9].innerHTML); 
	$('#faxInputA'	)		.val(cells[10].innerHTML); 
	$('#emailInputA')		.val(cells[11].innerHTML);
	$('#idperson')			.val(cells[12].innerHTML);
	$('#formulardiv').show();
}

function speichern() {

	var btn = document.getElementById('btnID').value;
	var row = btn.parentNode.parentNode;
	var cells = row.cells;
	cells[1].innerHTML = $('#anredeSelectA');
	cells[2].innerHTML = $('#titelSelectA').val();
	cells[3].innerHTML = $('#vornameInputA').val();
	cells[4].innerHTML = $('#nameInputA').val();
	cells[5].innerHTML = $('#strasseInputA').val();
	cells[6].innerHTML = $('#hausnrInputA').val();
	cells[7].innerHTML = $('#plzInputA').val();
	cells[8].innerHTML = $('#ortInputA').val();
	cells[9].innerHTML = $('#telefonInputA').val();
	cells[10].innerHTML = $('#faxInputA').val();
	cells[11].innerHTML = $('#emailInputA').val();
	cells[12].innerHTML = $('#idperson').val();

		$.getScript("classes/AJAXHelper.js", function() {
			doAJAX("updateProfil", ""+cells[1].innerHTML+","
					+cells[2].innerHTML+","
					+cells[3].innerHTML+","
					+cells[4].innerHTML+","
					+cells[5].innerHTML+","
					+cells[6].innerHTML+","
					+cells[8].innerHTML+","
					+cells[7].innerHTML+","
					+cells[9].innerHTML+","
					+cells[10].innerHTML+","
					+cells[11].innerHTML+","
					+cells[12].innerHTML, function(){if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
												alert(xmlhttp.responseText);
												}
											});
		});
	verstecken();
}

function verstecken() {
		$('#formulardiv').hide();
}

function neuesPasswort(){
	if(confirm(unescape("M%F6chten Sie das Passwort wirklich zur%FCcksetzen"))){
		$.getScript("classes/AJAXHelper.js", function() {
			doAJAX("resetPasswort", ""+$('#benutzernameA').val()+","
					+$('#idperson').val(), function() {
						if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
							if(xmlhttp.responseText){
								alert(xmlhttp.responseText);
							}
						}
					});
		});
	}
}

function neuerarzt(){
	$('#neuerArzt').show();
	$('#neuesPasswort').hide();
	$('#speichern').hide();
	$('#benutzernameA')		.val("");
	$('#anredeSelectA')		.val("");
	$('#titelSelectA')		.val("");
	$('#vornameInputA')		.val(""); 
	$('#nameInputA')		.val(""); 
	$('#strasseInputA')		.val(""); 
	$('#hausnrInputA')		.val("");
	$('#plzInputA')			.val(""); 
	$('#ortInputA')			.val(""); 
	$('#telefonInputA'	)	.val(""); 
	$('#faxInputA'	)		.val(""); 
	$('#emailInputA')		.val("");
	$('#formulardiv').show();
}

function neuerArztspeichern(){

	$.getScript("classes/AJAXHelper.js", function() {
		doAJAX("createArzt", ""+$('#anredeSelectA').val()+","
				+$('#titelSelectA').val()+","
				+$('#vornameInputA').val()+","
				+$('#nameInputA').val()+","
				+$('#strasseInputA').val()+","
				+$('#hausnrInputA').val()+","
				+$('#ortInputA').val()+","
				+$('#plzInputA').val()+","
				+$('#telefonInputA').val()+","
				+$('#faxInputA').val()+","
				+$('#emailInputA').val(), function() {
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						if(xmlhttp.responseText){
							alert(xmlhttp.responseText);
						}
					}
				});
	});
	
}

function deleteRow(btn) {
		if(confirm(unescape("M%F6chten Sie den Arzt wirklich l%F6schen%3F"))){
			
		var row = btn.parentNode.parentNode;
		var cells = row.cells;

		$.getScript("classes/AJAXHelper.js", function() {
			doAJAX("deleteLogin", cells[12].innerHTML, function() {
						if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
							if(xmlhttp.responseText){
								alert(xmlhttp.responseText);
							}
						}
					});
		});
		var row = btn.parentNode.parentNode;
	  	row.parentNode.removeChild(row);	
	};

	}

</script>
<div id=><span id="hinweismeldung"></span>

<div id="formulardiv">
<table id="alleBenutzer" style="width: 100%">
	<tr>
		<td><label style="width: 100%">Benutzername</label></td>
		<td><input id="benutzernameA" name="benutzername" style="width: 100%"
			onclick="this.select();" readonly></input></td>
	</tr>
	<tr>

		<td><label style="width: 100%">Anrede</label></td>
		<td><select id="anredeSelectA" style="width: 100%">
		<?php
		while ($anrede = $allAnrede->next()) {
			echo '<option value="' . $anrede['ABezeichnung'] . '">' . $anrede['ABezeichnung'] . '</option>';
		}
		?>
		</select></td>
		<td>Titel</td>
		<td><select id="titelSelectA" style="width: 100%">
		<?php
		while ($titel = $allTitel->next()) {
			echo '<option value="' . $titel['TBezeichnung'] . '">' . $titel['TBezeichnung'] . '</option>';
		}
		?>
		</select></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Vorname</label></td>
		<td><input id="vornameInputA" name="vornameInput" type="text"
			style="width: 100%" onclick="this.select();"></input></td>
		<td><label style="width: 100%">Name</label></td>
		<td><input id="nameInputA" style="width: 100%"
			onclick="this.select();"></input></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Telefon</label></td>
		<td><input id="telefonInputA" style="width: 100%"
			onclick="this.select();"></input></td>
		<td><label style="width: 100%">Faxnummer</label></td>
		<td><input id="faxInputA" style="width: 100%" onclick="this.select();"></input></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Stra&szlig;e</label></td>
		<td><input id="strasseInputA" style="width: 100%"
			onclick="this.select();"></input></td>
		<td><label style="width: 100%">HausNr</label></td>
		<td><input id="hausnrInputA" style="width: 100%" align="right"
			id="spinner" name="value"></td>
	</tr>
	<tr>
		<td><label style="width: 100%">PLZ</label></td>
		<td><input id="plzInputA" style="width: 100%" onclick="this.select();"></input></td>
		<td><label style="width: 100%">Ort</label></td>
		<td><input id="ortInputA" style="width: 100%" onclick="this.select();"></input></td>

	</tr>
	<tr>
		<td valign="top"><label style="width: 100%">E-Mail</label></td>
		<td valign="top"><input id="emailInputA" style="width: 100%"
			onclick="this.select();"></input></td>
		<td></td>
		<td></td>
		<td><input id="neuesPasswort" type="button" style="width: 100%"
			onclick="neuesPasswort('benuzerdaten')"
			value="Passwort zur&uuml;cksetzen"> <br>
		<br>
		<button style="width: 100%" onclick="verstecken()">abbrechen</button>
		<br>
		<input id="speichern" type="button" style="width: 100%"
			onclick="speichern()" value="speichern"> <input id="neuerArzt"
			type="button" style="width: 100%" onclick="neuerArztspeichern()"
			value="Arzt anlegen"></td>


		<td id="idperson" style="display: none"></td>
		<td id="btnID" style="display: none"></td>
		<td id="idperson" style="display: none"></td>
	</tr>
</table>
</div>
<br>
<div id="neuerarzt"><input type="button"
	style="width: 20%; float: right" onclick="neuerarzt()"
	value="Neuer Arzt"> <br>
</div>
<br>
<table class="table" id="benutzerdaten">
	<tr>
		<td>Benutzername</td>
		<td>Anrede</td>
		<td style="display: none">Titel</td>
		<td>Vorname</td>
		<td>Name</td>
		<td>Stra&szlig;e</td>
		<td>HausNr</td>
		<td>PLZ</td>
		<td>Ort</td>
		<td>Telefonnr</td>
		<td>Faxnummer</td>
		<td style="display: none">EmailAdresse</td>
		<td style="display: none">idPerson</td>
		<td></td>
	</tr>
	<?php
	$daten = $service->getAllAerzte();
	$i = 0;
	while ($datensatz = $daten->next())
	{
		echo '<tr>';
		echo '<td>'							. $datensatz['Benutzername'] 	. '</td>';
		echo '<td>'	. $datensatz['ABezeichnung'] 	. '</td>';
		echo '<td style="display:none">' 	. $datensatz['TBezeichnung'] 	. '</td>';
		echo '<td>' 						. $datensatz['Vorname'] 		. '</td>';
		echo '<td>' 						. $datensatz['Name'] 			. '</td>';
		echo '<td>' 						. $datensatz['Strasse'] 		. '</td>';
		echo '<td>' 						. $datensatz['Hausnummer'] 		. '</td>';
		echo '<td>' 						. $datensatz['PLZ'] 			. '</td>';
		echo '<td>' 						. $datensatz['Ort'] 			. '</td>';
		echo '<td>' 						. $datensatz['Telefonnummer'] 	. '</td>';
		echo '<td>' 						. $datensatz['Faxnummer'] 		. '</td>';
		echo '<td  style="display:none">' 	. $datensatz['EMailAdresse'] 	. '</td>';
		echo '<td  style="display:none">' 	. $datensatz['idPerson']	 	. '</td>';
		echo '<td>
				<input type="button" style="width: 100%"
				onclick="deleteRow(this)" value="L&ouml;schen">
				<br>
				<input type="button" style="width: 100%"
				onclick="auswahlRow(this)" value="&Auml;ndern"></td>';
		echo '</tr>';
		$i++;
	}
	?>
</table>
</div>

</body>
</html>
